Home:ALL Converter>How to use custom error settings for JWT middleware

How to use custom error settings for JWT middleware

Ask Time:2018-11-18T05:46:39         Author:C0ol_Cod3r

Json Formatter

I have followed the cook books guide to the letter, found here https://echo.labstack.com/cookbook/jwt

But when using the JWT middleware I am having some issues with adding custom error messages. Login works fine, even to the point of not giving details (username & password) that returns a 404.

But when the JWT is missing it returns a 400, I want it to also return a 404.

So in my research I found this, https://forum.labstack.com/t/custom-error-message-in-jwt-middleware/325/3 which lists the following middleware.ErrJWTMissing & middleware.ErrJWTInvalid But is very unclear on how to set these?

I have tried setting them as vars on the router file, like so

var (
  ErrJWTInvalid = echo.NewHTTPError(http.StatusTeapot, "test 104")
  ErrJWTMissing = echo.NewHTTPError(http.StatusTeapot, "test 103")
)

But the error that sill comes back to me is a 400 and not a 418 (as this is just a test). So what am I doing wrong?

Author:C0ol_Cod3r,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/53355859/how-to-use-custom-error-settings-for-jwt-middleware
Ropelatto :

You can change the HTTP code and message this way.\n\nfunc init() {\n middleware.ErrJWTMissing.Code = 401\n middleware.ErrJWTMissing.Message = \"Unauthorized\"\n}\n",
2019-08-21T16:46:41
yy